﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class ShootAction:CharacterAction
    {
        private const int speed = 20,
                        pHealth = 20;
        private Projectile bullet;
        private int minDamage;

        public ShootAction(Character c, bool persistant, int row, int colEnd, int count, int lockoutLevel, int minDamage)
            : base(c, persistant, row, colEnd, count, lockoutLevel)
        {
            this.minDamage = minDamage;
            bullet = new Projectile("Bullet", pHealth, Sprites.CreateSprite(Resources.LoadBitmap("projectile.png")), c);
        }

        public override void DoAction(GameController gc)
        {
            Player enemy = (gc.GameStages.Peek().FindPlayer() as Player);
            if (enemy == null) return;

            if (!IsActive)
            {
                IsActive = true;
                c.GlobalLockout = true;
                GlobalConst.Utils.ActivateAnimationRow(c.ObjectSprite, row + c.offSetSpriteRow(), colEnd, count);
                bullet.IsActive = true;
                gc.GameStages.Peek().ToAdd.Add(bullet);
            }
            if (bullet.IsActive)
                bullet.V = VectorPath(enemy);
            else
                Reset(gc);
            
        }

        public Vector VectorPath(Player enemy)
        {
            Point2D spriteOffset;
            spriteOffset.x = Geometry.CenterPoint(c.ObjectSprite).x - c.ShootOffsetX();
            spriteOffset.y = Geometry.CenterPoint(c.ObjectSprite).y - c.ShootOffsetY;
            Vector v = Geometry.VectorFromPoints(spriteOffset, Geometry.CenterPoint(enemy.ObjectSprite));
            v = Geometry.VectorMultiply(Geometry.UnitVector(v), speed);
            return v;
        }

        public override void Reset(GameController gc)
        {
            IsActive = false;
            
            c.GlobalLockout = false;
            GlobalConst.Utils.ActivateAnimationRow(c.ObjectSprite, c.offSetSpriteRow(), GlobalConst.DefaultColEnd, GlobalConst.DefaultFPC);
        }

    }
}
